package leecode;

/**
 * 第十一天
 */
//第一题
public class LeetCode8 {
    public ListNode deleteNode(ListNode head, int val) {
        if (head.val == val) {
            head = head.next;
        }
        ListNode cur1 = head;
        ListNode cur2 = cur1.next;
        while (cur2 != null) {
            if (cur2.val == val) {
                cur1.next = cur2.next;
                return head;
            }
            cur1 = cur1.next;
            cur2 = cur2.next;
        }
        return head;
    }
    // 第二题
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode cur=head;
        int count=0;
        while(cur!=null){
            count++;
            cur=cur.next;
        }
        int b=count-k;
        while (k-->0){
            head=head.next;
        }
        return head;
    }
}
